package Cantella::DJabberd::Web::UI::ViewPort::Layout;

use Reaction::Class;
use aliased 'Reaction::UI::ViewPort';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::Menu';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::List';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::Static';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::SidebarItem';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::User::Auth';

#extends 'Reaction::UI::ViewPort';
class Layout, is ViewPort, which {
  has menu    => (is => 'ro', isa => ViewPort, lazy_build => 1);
  has submenu => (is => 'ro', isa => ViewPort, lazy_build => 1);
  has auth_vp => (is => 'ro', isa => ViewPort, lazy_build => 1);
  has sidebar => (is => 'ro', isa => ViewPort, lazy_build => 1);

  has scripts     => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
  has stylesheets => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);

  #implements _build_scripts => as { [] };
  #implements _build_stylesheets => as { [] };
  sub _build_scripts { [] }
  sub _build_stylesheets { [] }

  sub _build_menu {
  #implements _build_menu => as {
    my $self = shift;
    Menu->new
      (
       ctx      => $self->ctx,
       location => join('-', $self->location, 'menu'),
      );
  }

  sub _build_submenu {
  #implements _build_submenu => as {
    my $self = shift;
    Menu->new
      (
       ctx      => $self->ctx,
       location => join('-', $self->location, 'submenu'),
      );
  }

  sub _build_sidebar {
  #implements _build_sidebar => as {
    my $self = shift;
    List->new
      (
       ctx        => $self->ctx,
       location   => join('-', $self->location, 'sidebar'),
       item_class => SidebarItem,
       layout     => 'sidebar'
      );
  }

  override child_event_sinks => sub {
    my $self = shift;
    ( $self->auth_vp, $self->menu, $self->sidebar, super() );
  };

  sub title {
  #implements title => as {
    my $self = shift;
    $self->ctx->stash->{window}->title;
  }

  sub _build_auth_vp {
  #implements _build_auth_vp => as {
    my $self = shift;
    my $auth_model = $self->ctx->model('Admin')->users;
    Auth->new(
              ctx        => $self->ctx,
              location   => join('-', $self->location, 'auth'),
              auth_model => $auth_model,
             );
  }
};

1;

__END__;
